package com.dwd.order.controller;

import com.dwd.basic.utils.AjaxResult;
import com.dwd.basic.utils.PageBean;
import com.dwd.basic.utils.SystemContext;
import com.dwd.order.pojo.ProductOrder;
import com.dwd.order.query.ProductOrderQuery;
import com.dwd.order.service.IProductOrderService;
import com.dwd.servicemanager.pojo.Product;
import com.dwd.servicemanager.query.ProductQuery;
import com.dwd.user.pojo.LoginInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description: TODO
 * @Author 汶狄
 * @Date 2021/1/27 17:57
 * @Version 1.0
 */
@RestController
@RequestMapping("/productOrder")
public class ProductOrderController {
    @Autowired
    private IProductOrderService productOrderService;

    @PostMapping("/submitOrder")
    public AjaxResult submitOrder(@RequestBody Map<String, Object> map, HttpServletRequest httpServletRequest) {
        try {
            LoginInfo loginInfo = SystemContext.getLoginInfo(httpServletRequest);
            String result = productOrderService.submitOrder(map, loginInfo);
            return AjaxResult.me().setResultObj(result);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }

    /**
     * 产品订单展示分页
     * @param productOrderQuery
     * @return
     */
    @PostMapping
    public PageBean<ProductOrder> queryPage(@RequestBody ProductOrderQuery productOrderQuery) {
        PageBean<ProductOrder> productOrderPageBean = productOrderService.queryPage(productOrderQuery);
        return productOrderPageBean;
    }
}



















